package com.sxm.yiwei.pinche;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.sxm.yiwei.R;
import com.sxm.yiwei.base.BaseActivity;
import com.sxm.yiwei.beans.pinche.Order;
import com.sxm.yiwei.constant.Common;
import com.sxm.yiwei.constant.Constant;
import com.sxm.yiwei.tools.CircleTransform;
import com.sxm.yiwei.utils.HandleDataUtil;
import com.sxm.yiwei.views.AmountView;

import java.io.Serializable;


public class ChangeTicketActivity extends BaseActivity implements View.OnClickListener {
    private RelativeLayout rl_back;
    private TextView tv_title;
    private TextView tv_change_style;
    private TextView tv_change_desciption;
    private TextView tv_seats_bought;
    private TextView tv_total_price;
    private TextView tv_phone;
    private TextView tv_passenger_words;
    private TextView tv_start_pos;
    private TextView tv_end_pos;
    private TextView tv_order_id;
    private TextView tv_start_time;
    private TextView tv_compensation_money;
    private TextView tv_return_back;
    private TextView tv_pinche_rule;
    private TextView tv_pinche_count_rule;
    private Button btn_change_ticket;
    private CheckBox checkBox;
    private ScrollView scrollView;
    private Order order;
    private int go_type;
    private ImageView iv_icon;

    @Override
    public void setContentView() {
        setContentView(R.layout.activity_change_ticket);
    }

    @Override
    public void initData() {
        order = (Order) getIntent().getSerializableExtra("order");
        go_type = getIntent().getIntExtra("go_type",-1);
        tv_title.setText("改签");
        if (go_type==Constant.LONG){
            tv_change_style.setText("乘客—"+"长途改签");
        }else if (go_type==Constant.CITY){
            tv_change_style.setText("乘客—"+"同城改签");
        }else if (go_type==Constant.TRAVEL){
            tv_change_style.setText("乘客—"+"旅游改签");
        }else if (go_type==Constant.LONG_HURRY){
            tv_change_style.setText("乘客—"+"长途急件改签");
        }else {
            showToast("go_type没有获取到");
        }
        tv_seats_bought.setText(order.getSeats()+"");
        tv_total_price.setText(order.getTotal_money()+"");
        Picasso.with(this).load(Common.IMAGE_HOST+order.getIcon()).error(R.mipmap.morentouxiang).transform(new CircleTransform()).into(iv_icon);
        tv_phone.setText(order.getPhone());
        tv_passenger_words.setText("我的留言："+order.getWords());
        tv_start_pos.setText(order.getStart_place());
        tv_end_pos.setText(order.getEnd_place());
        tv_order_id.setText(order.getOrder_code());
        tv_start_time.setText(order.getDepart_time());
    }

    @Override
    public void initView() {
        rl_back = (RelativeLayout)findViewById(R.id.rl_back);
        tv_title = (TextView)findViewById(R.id.tv_title);
        tv_change_style = (TextView)findViewById(R.id.tv_change_style);
        tv_change_desciption = (TextView)findViewById(R.id.tv_change_desciption);
        tv_seats_bought = (TextView)findViewById(R.id.tv_seats_bought);
        tv_total_price = (TextView)findViewById(R.id.tv_total_price);
        tv_phone = (TextView)findViewById(R.id.tv_phone);
        tv_passenger_words = (TextView)findViewById(R.id.tv_passenger_words);
        tv_start_pos = (TextView)findViewById(R.id.tv_start_pos);
        tv_end_pos = (TextView)findViewById(R.id.tv_end_pos);
        tv_order_id = (TextView)findViewById(R.id.tv_order_id);
        tv_start_time = (TextView)findViewById(R.id.tv_start_time);
        iv_icon = (ImageView)findViewById(R.id.iv_icon);
        checkBox = (CheckBox) findViewById(R.id.checkbox);
        tv_pinche_rule = (TextView)findViewById(R.id.tv_pinche_rule);
        tv_pinche_count_rule = (TextView)findViewById(R.id.tv_pinche_count_rule);
        scrollView = (ScrollView)findViewById(R.id.scrollView);
        scrollView.smoothScrollTo(0,0);
        btn_change_ticket = (Button)findViewById(R.id.btn_change_ticket);
        btn_change_ticket.setBackgroundDrawable(getResources().getDrawable(R.drawable.commit_order_btn_disable));
        btn_change_ticket.setEnabled(false);
    }

    @Override
    public void initListener() {
        rl_back.setOnClickListener(this);
        tv_pinche_rule.setOnClickListener(this);
        tv_pinche_count_rule.setOnClickListener(this);
        btn_change_ticket.setOnClickListener(this);

        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (!b){
                    btn_change_ticket.setBackgroundDrawable(getResources().getDrawable(R.drawable.commit_order_btn_disable));
                    btn_change_ticket.setEnabled(false);
                }else {
                    btn_change_ticket.setBackgroundDrawable(getResources().getDrawable(R.drawable.commit_order_btn_enable));
                    btn_change_ticket.setEnabled(true);
                }
            }
        });
    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()){
            case R.id.tv_pinche_count_rule:
                Intent iPinCountRule = new Intent(this, RuleActivity.class);
                iPinCountRule.putExtra("type", Constant.PINCHE_COUNT_RULE);
                startActivity(iPinCountRule);
                break;
            case R.id.tv_pinche_rule:
                Intent iPinRule = new Intent(this, RuleActivity.class);
                iPinRule.putExtra("type",Constant.PINCHE_RULE);
                startActivity(iPinRule);
                break;
            case R.id.btn_change_ticket:
                Intent intent = new Intent(this, SelectChangeRouteActivity.class);
                intent.putExtra("order",order);
                startActivity(intent);
                break;
        }
    }


}
